﻿#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    // 219. 存在重复元素 II
    bool containsNearbyDuplicate(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        for (int i = 1; i <= nums.size(); i++)
        {
            if (hash[nums[i - 1]])
                if (abs(hash[nums[i - 1]] - i) <= k)
                    return true;
            hash[nums[i - 1]] = i;
        }
        return false;
    }
};

int main()
{
    vector<int> v{ 99, 99 };
    cout << Solution().containsNearbyDuplicate(v, 3) << endl;

    return 0;
}